package com.telecomyt.jwportal.utils;

import android.content.ContentResolver;
import android.content.Context;
import android.database.Cursor;
import android.net.Uri;
import android.provider.CallLog;

import com.telecomyt.jwportal.activity.conversation.bean.CallInfoBean;

import java.util.ArrayList;
import java.util.List;

/**
 * @author created by chengDa
 * @time 2020/9/9  11:01
 * @description
 */
public class ContactsMsgUtils {
    public static List<CallInfoBean> getCallLog(Context context) {
        List<CallInfoBean> infos = new ArrayList<CallInfoBean>();
        ContentResolver cr = context.getContentResolver();
        Uri uri = CallLog.Calls.CONTENT_URI;
        String[] projection = new String[]{CallLog.Calls.CACHED_NAME,CallLog.Calls.NUMBER, CallLog.Calls.DATE,
                CallLog.Calls.TYPE,CallLog.Calls.DURATION};
        Cursor cursor = cr.query(uri, projection, null, null, null);
        while (cursor.moveToNext()) {
            String name = cursor.getString(cursor.getColumnIndex(CallLog.Calls.CACHED_NAME));
            String number = cursor.getString(cursor.getColumnIndex(CallLog.Calls.NUMBER));
            long date = cursor.getLong(cursor.getColumnIndex(CallLog.Calls.DATE));
            int type = cursor.getInt(cursor.getColumnIndex(CallLog.Calls.TYPE));
            int duration = cursor.getInt(cursor.getColumnIndex(CallLog.Calls.DURATION));
            infos.add(new CallInfoBean(name,number, date, type,duration));
        }
        cursor.close();
        return infos;
    }

}
